package edu.sdjzu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.sdjzu.dto.CreateArticleRequest;
import edu.sdjzu.entity.Article;
import edu.sdjzu.mapper.ArticleMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ContentService {

    private final ArticleMapper articleMapper;

    public ContentService(ArticleMapper articleMapper) {
        this.articleMapper = articleMapper;
    }

    public void createArticle(CreateArticleRequest request) {
        Article article = new Article();
        article.setTitle(request.getTitle());
        article.setContent(request.getContent());
        article.setUserId(1L);
        articleMapper.insert(article);
    }

    public List<Article> getArticlesByUserId(Long userId) {
        return articleMapper.selectList(
                new QueryWrapper<Article>().eq("user_id", userId)
        );
    }

    public Article getArticleById(Long id) {
        return articleMapper.selectById(id);
    }
}
